//
//  CQBaseModel.m
//  HiChat
//
//  Created by wqiong on 16/1/10.
//  Copyright © 2016年 wqiong. All rights reserved.
//

#import "CQBaseModel.h"

@implementation CQBaseModel

- (instancetype)initWithDic:(NSMutableDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

//便利构造器
+ (instancetype)baseModelWithDic:(NSMutableDictionary *)dic {
    //使用多态的方式进行对象的创建
    id obj = [[[self class] alloc] initWithDic:dic];
    return [obj autorelease];
}

+ (NSMutableArray *)baseModelWithArr:(NSMutableArray *)arr
{
    // 创建一个数组, 用来装model
    NSMutableArray *modelArr = [NSMutableArray array];
    for (NSMutableDictionary *dic in arr) {
        @autoreleasepool {
            // 通过便利构造器方式创建对象.
            id model = [[self class] baseModelWithDic:dic];
            // 把对象添加到数组中
            [modelArr addObject:model];
        }
    }
    return modelArr;
    
}



@end
